{include file='common/_meta' /}
<body>
<div class="container">
	<div class="layui-row">
        <div class="layui-col-md12 breadcrumb">
    		<span class="layui-breadcrumb">
    			<a><cite>渠道管理菜单</cite></a>
    			<a><cite>错误对照表</cite></a>
    		</span>
        </div>
    </div>

    <div class="layui-row">

    	<form class="layui-form" action="" lay-filter="" style="padding-top: 15px;" id="search-form">

    		<div class="layui-col-sm3">
                <div class="layui-form-item">
                    <label class="layui-form-label">对照码：</label>
                    <div class="layui-input-block">
                        <input type="text" name="code" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>

    		<div class="layui-col-sm4">
				<div class="layui-input-block">
			      	<button class="layui-btn custom-sm-fluid" lay-submit lay-filter="custom-search">搜索</button>
			    </div>
    		</div>

    	</form>

    </div>

	<div class="layui-col-md12">

		<table class="layui-hide" id="initdate" lay-filter="datatable"></table>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <!-- <button class="layui-btn layui-btn-sm" lay-event="add">新增</button>
                <button class="layui-btn layui-btn-sm" lay-event="dao">导出</button> -->
            </div>
        </script>

        <script type="text/html" id="barDemo">
          	<a class="layui-btn layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i></a>
          	<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i></a>
        </script>

	</div>

</div>
{include file="common/_footer"}

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="{:$Think.config.__STATIC__}/lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript">
layui.use('table', function() {

	var table = layui.table;
	var layer = layui.layer;
	var form  = layui.form;

    var tableIns = table.render({
        elem: '#initdate'
        ,url:'{:url('ErrorComparison/index')}'
        ,cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
        ,toolbar: '#toolbarDemo'//默认工具栏
        ,defaultToolbar: []
        ,method:'get'//请求方式
        ,where: {api: 1}
        ,page:true//开启分页
        ,limit:15//每页记录数
        ,limits: [15,20,30,40,50,60,70,80,90]
        ,cols: [[
            {type:'numbers', title: '序号'}
            ,{field:'code', title: '对照码'}
            ,{field:'desc', title: '描述'}
            // ,{fixed:'right', title: '操作', toolbar: '#barDemo', width: 100, unresize: true}
        ]]
    });

    //监听头工具栏事件
    table.on('toolbar(datatable)', function(obj){

        switch(obj.event) {

            case 'add':
                layer.open({
                    type: 2,
                    title: '新增',
                    area: ['100%', '100%'],
                    content: '{:url('ErrorComparison/add')}'
                });
                break;
            case 'dao':
                window.open("{:url('ErrorComparison/listExport')}");
                break;
        };
    });

    //监听工具条
  	table.on('tool(datatable)', function(obj) {

        var data = obj.data;

        switch(obj.event) {

            case 'edit':
                layer.open({
                    type: 2,
                    title: '编辑',
                    area: ['100%', '100%'],
                    content: '{:url('ErrorComparison/edit')}' + '?id=' + data.id
                });
                break;

            case 'del':
                layer.confirm('真的删除行么', function(index) {
                	obj.del();
                	layer.close(index);

                	$.ajax({
                	    type: 'POST',
                	    url: '{:url('ErrorComparison/del')}',
                	    data : {'id': data.id},
                	    success: function(data) {

                	        if (data == 'success') {

                                obj.del();

                                layer.msg('已删除!', {icon:1,time:1000}, function() {
                                    tableIns.reload({
                                        where: {code: $('#search-form').find('[name=code]').val(), api: 1}
                                        ,page: {curr: 1}
                                    });
                                });
                	        } else {

                                layer.msg('删除失败',{icon: 5,time:3000});
                                return false;
                            }
                	    },
                	    error:function(data) {
                	        console.log(data.msg);
                	    },
                	});
              	});

                break;
        };

    });

  	// 监听搜索事件
    form.on('submit(custom-search)', function(data) {

      	tableIns.reload({
        	where: {
	          	code: data.field.code
	          	,api: 1
        	}
        	,page: {
          		curr: 1
        	}
      	});

      	return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
    });

});
</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>